/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package foxmob.mlts.viewcontroller.student;

import foxmob.mlts.viewcontroller.*;
import foxmob.mlts.component.FileManager;
import foxmob.mlts.controller.setter.SetDefaultTestFormController;
import foxmob.mlts.model.QuestionPaper;
import foxmob.mlts.model.Section;
import foxmob.mlts.model.Timer;
import foxmob.mlts.view.student.SectionInformationFrame;
import foxmob.mlts.viewcontroller.setter.SetDefaultTestForm;
import foxmob.mlts.viewcontroller.student.ScorePanel;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.GridLayout;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.JScrollPane;
import javax.swing.ScrollPaneConstants;

/**
 *
 * @author zpf16z
 */
public class QuestionPaperForm extends javax.swing.JFrame {

    /**
     * Creates new form QuestionPaperForm
     */
    private int minutes;
    private double seconds;
    private Thread mb;
    private boolean isRun;
    
    public static FileManager manager = FileManager.getInstanceObject();
    public static QuestionPaper testRecord;
    private static int index = 0;
    public static int questionNumber = 0;
    public static int finishedQuestions = 0;
    public static int process;
    public QuestionPaperForm() {
       initComponents();
//        Timer timer = new Timer(this.jLabelTime, 30000);
//        timer.start();
//        JScrollPane jsp = new SectionJScrollPane().loadQuestions(testRecord.getSections().get(index));
//        this.jPanelMain.add(jsp);
//        this.jPanelMain.repaint();
    }
    
    public QuestionPaperForm(Section s, int indexSection) {
        initComponents();
        load(s);
//        try {
//            this.jLabelNavigate.setText(s.getTitle());
//            //Timer timer = new Timer(this.jLabelTime, s.getRemainingSeconds() * 1000);
//            Timer timer = new Timer(this.jLabelTime, 10 * 1000);
//            timer.start();
//            JScrollPane jsp = new SectionJScrollPane().loadQuestions(s);
//            
//            //this.jPanelMain.removeAll();
//            this.jPanelMain.add(jsp);
//            this.jPanelMain.repaint();
//        } catch (Exception e) {
            //
//        }
    }
    
    public void loadTestRecord() {
        try {
            String keyName = SetDefaultTestFormController.DEFAULT_TEST_PREFERENCE;
            String fileName = 
                    manager.getObjectFromProperties(keyName);
            // get Record
            this.testRecord = manager.getTestRecord(fileName);
            load(this.testRecord.getSections().get(0));
        } catch (IOException ex) {
            Logger.getLogger(QuestionPaperForm.class.getName()).log(Level.SEVERE, null, ex);
        }

        
    }

    public void load(Section s) {
        //this.removeAll();
        //initComponents();
        this.questionNumber = 0;
        finishedQuestions = 0;
        try {
            this.jLabelNavigate.setText("  " + s.getTitle());
            JScrollPane jsp = new SectionScrollPanel().loadQuestions(s);
            //his.jPanelMain.remove(0);
            this.jPanelMain.add(jsp);
            this.jPanelMain.repaint();
            this.setVisible(false);
                        
            Timer timer = new Timer(this.jLabelTime,this.jProgressBarProcess , s.getRemainingSeconds() * 1000, this.jButtonSubmit);
            SectionInformationFrame sf = new SectionInformationFrame(s, timer, this);
            sf.setVisible(true);
            sf.setAlwaysOnTop(true);
            
            System.out.println(s.getRemainingSeconds());
        } catch (Exception e) {
            //
        }
    }

    

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jDialogSave = new javax.swing.JDialog();
        jButtonOK = new javax.swing.JButton();
        jLabelInformation1 = new javax.swing.JLabel();
        jDialogSubmit = new javax.swing.JDialog();
        jLabelInformation2 = new javax.swing.JLabel();
        jButtonNext = new javax.swing.JButton();
        jDialogFinish = new javax.swing.JDialog();
        jLabelInformation3 = new javax.swing.JLabel();
        jButtonGetScore = new javax.swing.JButton();
        jPanelBotom = new javax.swing.JPanel();
        jLabelNavigate = new javax.swing.JLabel();
        jLabelLeftBlank = new javax.swing.JLabel();
        jPanelBar = new javax.swing.JPanel();
        jProgressBarProcess = new javax.swing.JProgressBar();
        jLabelRightBlank = new javax.swing.JLabel();
        jLabelTime = new javax.swing.JLabel();
        jButtonSave = new javax.swing.JButton();
        jButtonSubmit = new javax.swing.JButton();
        jPanelMain = new javax.swing.JPanel();
        menuBar = new javax.swing.JMenuBar();
        fileMenu = new javax.swing.JMenu();
        jCheckBoxMenuItemStudent = new javax.swing.JCheckBoxMenuItem();
        jSeparator1 = new javax.swing.JPopupMenu.Separator();
        jMenuItemExit = new javax.swing.JMenuItem();
        editMenu = new javax.swing.JMenu();
        cutMenuItem = new javax.swing.JMenuItem();
        copyMenuItem = new javax.swing.JMenuItem();
        pasteMenuItem = new javax.swing.JMenuItem();
        deleteMenuItem = new javax.swing.JMenuItem();
        helpMenu = new javax.swing.JMenu();
        contentsMenuItem = new javax.swing.JMenuItem();
        aboutMenuItem = new javax.swing.JMenuItem();

        jDialogSave.setLocationByPlatform(true);
        jDialogSave.setResizable(false);

        jButtonOK.setText("OK");
        jButtonOK.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonOKActionPerformed(evt);
            }
        });

        jLabelInformation1.setText("Answers have been saved!");

        org.jdesktop.layout.GroupLayout jDialogSaveLayout = new org.jdesktop.layout.GroupLayout(jDialogSave.getContentPane());
        jDialogSave.getContentPane().setLayout(jDialogSaveLayout);
        jDialogSaveLayout.setHorizontalGroup(
            jDialogSaveLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jDialogSaveLayout.createSequentialGroup()
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .add(jButtonOK)
                .add(34, 34, 34))
            .add(jDialogSaveLayout.createSequentialGroup()
                .add(58, 58, 58)
                .add(jLabelInformation1)
                .addContainerGap(278, Short.MAX_VALUE))
        );
        jDialogSaveLayout.setVerticalGroup(
            jDialogSaveLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jDialogSaveLayout.createSequentialGroup()
                .add(58, 58, 58)
                .add(jLabelInformation1)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 78, Short.MAX_VALUE)
                .add(jButtonOK)
                .add(19, 19, 19))
        );

        jLabelInformation2.setText("Answers have been submited!");

        jButtonNext.setText("Next");
        jButtonNext.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonNextActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jDialogSubmitLayout = new org.jdesktop.layout.GroupLayout(jDialogSubmit.getContentPane());
        jDialogSubmit.getContentPane().setLayout(jDialogSubmitLayout);
        jDialogSubmitLayout.setHorizontalGroup(
            jDialogSubmitLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jDialogSubmitLayout.createSequentialGroup()
                .add(50, 50, 50)
                .add(jLabelInformation2)
                .addContainerGap(263, Short.MAX_VALUE))
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jDialogSubmitLayout.createSequentialGroup()
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .add(jButtonNext)
                .add(21, 21, 21))
        );
        jDialogSubmitLayout.setVerticalGroup(
            jDialogSubmitLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jDialogSubmitLayout.createSequentialGroup()
                .add(50, 50, 50)
                .add(jLabelInformation2)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 89, Short.MAX_VALUE)
                .add(jButtonNext)
                .add(16, 16, 16))
        );

        jLabelInformation3.setText("Answers have been submited! ");

        jButtonGetScore.setText("Get Score");
        jButtonGetScore.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonGetScoreActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jDialogFinishLayout = new org.jdesktop.layout.GroupLayout(jDialogFinish.getContentPane());
        jDialogFinish.getContentPane().setLayout(jDialogFinishLayout);
        jDialogFinishLayout.setHorizontalGroup(
            jDialogFinishLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jDialogFinishLayout.createSequentialGroup()
                .add(50, 50, 50)
                .add(jLabelInformation3)
                .addContainerGap(259, Short.MAX_VALUE))
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jDialogFinishLayout.createSequentialGroup()
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .add(jButtonGetScore)
                .add(21, 21, 21))
        );
        jDialogFinishLayout.setVerticalGroup(
            jDialogFinishLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jDialogFinishLayout.createSequentialGroup()
                .add(50, 50, 50)
                .add(jLabelInformation3)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 89, Short.MAX_VALUE)
                .add(jButtonGetScore)
                .add(16, 16, 16))
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setName("FoxMob"); // NOI18N

        jPanelBotom.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanelBotom.setLayout(new javax.swing.BoxLayout(jPanelBotom, javax.swing.BoxLayout.LINE_AXIS));

        jLabelNavigate.setText("  Student->Section1");
        jLabelNavigate.setHorizontalTextPosition(javax.swing.SwingConstants.LEFT);
        jPanelBotom.add(jLabelNavigate);

        jLabelLeftBlank.setText("          ");
        jPanelBotom.add(jLabelLeftBlank);

        jPanelBar.setLayout(new java.awt.BorderLayout());
        jPanelBar.add(jProgressBarProcess, java.awt.BorderLayout.CENTER);

        jPanelBotom.add(jPanelBar);

        jLabelRightBlank.setText("          ");
        jPanelBotom.add(jLabelRightBlank);

        jLabelTime.setText("TimeLeft: ....  ");
        jPanelBotom.add(jLabelTime);

        jButtonSave.setText("Save");
        jButtonSave.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButtonSaveMouseClicked(evt);
            }
        });
        jButtonSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonSaveActionPerformed(evt);
            }
        });

        jButtonSubmit.setText("Submit");
        jButtonSubmit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonSubmitActionPerformed(evt);
            }
        });

        jPanelMain.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanelMain.setLayout(new java.awt.BorderLayout());

        fileMenu.setMnemonic('f');
        fileMenu.setText("File");

        jCheckBoxMenuItemStudent.setSelected(true);
        jCheckBoxMenuItemStudent.setText("Student");
        fileMenu.add(jCheckBoxMenuItemStudent);
        fileMenu.add(jSeparator1);

        jMenuItemExit.setText("Exit");
        jMenuItemExit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemExitActionPerformed(evt);
            }
        });
        fileMenu.add(jMenuItemExit);

        menuBar.add(fileMenu);

        editMenu.setMnemonic('e');
        editMenu.setText("Edit");

        cutMenuItem.setMnemonic('t');
        cutMenuItem.setText("Cut");
        editMenu.add(cutMenuItem);

        copyMenuItem.setMnemonic('y');
        copyMenuItem.setText("Copy");
        editMenu.add(copyMenuItem);

        pasteMenuItem.setMnemonic('p');
        pasteMenuItem.setText("Paste");
        editMenu.add(pasteMenuItem);

        deleteMenuItem.setMnemonic('d');
        deleteMenuItem.setText("Delete");
        editMenu.add(deleteMenuItem);

        menuBar.add(editMenu);

        helpMenu.setMnemonic('h');
        helpMenu.setText("Help");

        contentsMenuItem.setMnemonic('c');
        contentsMenuItem.setText("Contents");
        helpMenu.add(contentsMenuItem);

        aboutMenuItem.setMnemonic('a');
        aboutMenuItem.setText("About");
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        setJMenuBar(menuBar);

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .add(jButtonSave, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 86, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(18, 18, 18)
                .add(jButtonSubmit)
                .add(18, 18, 18))
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanelMain, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(jPanelBotom, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 810, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .add(jPanelBotom, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 36, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanelMain, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 307, Short.MAX_VALUE)
                .add(18, 18, 18)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jButtonSave)
                    .add(jButtonSubmit))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jMenuItemExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemExitActionPerformed
        // TODO add your handling code here:
        System.exit(0);
    }//GEN-LAST:event_jMenuItemExitActionPerformed

    private void jButtonSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSaveActionPerformed
        try {
            // TODO add your handling code here:

            saveAnswers();
        } catch (IOException ex) {
            Logger.getLogger(QuestionPaperForm.class.getName()).log(Level.SEVERE, null, ex);
        }
        this.jDialogSave.setSize(500, 200);
        this.jDialogSave.setAlwaysOnTop(true);
        this.jDialogSave.show();
        
        
        
    }//GEN-LAST:event_jButtonSaveActionPerformed

    private void jButtonSaveMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButtonSaveMouseClicked
//        // TODO add your handling code here:
//        MCQPanel p = new MCQPanel();
//        JButton b = new JButton();
//        b.setText("2313123213213");
        
        //Container   content=this.getContentPane(); 
        //content.add(b);
        //this.validate();
        
        
    }//GEN-LAST:event_jButtonSaveMouseClicked

    private void jButtonSubmitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSubmitActionPerformed
        // TODO add your handling code here:]
        

//        save();
//        if( isTheLastSection){
//            this.jDialogFinish.setSize(500,200);
//            this.jDialogFinish.setAlwaysOnTop(true);
//            this.jDialogFinish.show();
//        }else{
//            this.jDialogSubmit.setSize(500, 200);
//            this.jDialogSubmit.setAlwaysOnTop(true);
//            this.jDialogSubmit.show();
//        }
        
        try {
            // TODO add your handling code here:

            saveAnswers();
        } catch (IOException ex) {
            Logger.getLogger(QuestionPaperForm.class.getName()).log(Level.SEVERE, null, ex);
        }
        if (index + 1 < testRecord.getSectionsLength()) {
            this.jDialogSubmit.setSize(500, 200);
            this.jDialogSubmit.setAlwaysOnTop(true);
            this.jDialogSubmit.show();
        } else {
            this.jDialogFinish.setSize(500, 200);
            this.jDialogFinish.setAlwaysOnTop(true);
            this.jDialogFinish.show();
        }

    }//GEN-LAST:event_jButtonSubmitActionPerformed

    private void jButtonOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonOKActionPerformed
        // TODO add your handling code here:
        this.jDialogSave.hide();
    }//GEN-LAST:event_jButtonOKActionPerformed

    private void jButtonNextActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonNextActionPerformed
        // TODO add your handling code here:
        
        index += 1;
        QuestionPaperForm questionPaper = new QuestionPaperForm(testRecord.getSections().get(index), index); 
        this.jDialogSubmit.hide();
        this.hide();
//        try {
//            Thread.sleep(1000);
//        } catch (InterruptedException ex) {
//            Logger.getLogger(QuestionPaperForm.class.getName()).log(Level.SEVERE, null, ex);
//        }
        //this.dispose();
        questionPaper.setVisible(false);

    }//GEN-LAST:event_jButtonNextActionPerformed

    private void jButtonGetScoreActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonGetScoreActionPerformed
        // TODO add your handling code here:
        this.hide();
        this.jDialogFinish.hide();
        ScorePanel scoreForm = new ScorePanel();
        scoreForm.setScore(testRecord.getScore());
        scoreForm.setVisible(true);
        
    }//GEN-LAST:event_jButtonGetScoreActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(QuestionPaperForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(QuestionPaperForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(QuestionPaperForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(QuestionPaperForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                new QuestionPaperForm(testRecord.getSections().get(index), index).setVisible(true);
            }
        });
    }
    
    
    
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem aboutMenuItem;
    private javax.swing.JMenuItem contentsMenuItem;
    private javax.swing.JMenuItem copyMenuItem;
    private javax.swing.JMenuItem cutMenuItem;
    private javax.swing.JMenuItem deleteMenuItem;
    private javax.swing.JMenu editMenu;
    private javax.swing.JMenu fileMenu;
    private javax.swing.JMenu helpMenu;
    private javax.swing.JButton jButtonGetScore;
    private javax.swing.JButton jButtonNext;
    private javax.swing.JButton jButtonOK;
    private javax.swing.JButton jButtonSave;
    private javax.swing.JButton jButtonSubmit;
    private javax.swing.JCheckBoxMenuItem jCheckBoxMenuItemStudent;
    private javax.swing.JDialog jDialogFinish;
    private javax.swing.JDialog jDialogSave;
    private javax.swing.JDialog jDialogSubmit;
    private javax.swing.JLabel jLabelInformation1;
    private javax.swing.JLabel jLabelInformation2;
    private javax.swing.JLabel jLabelInformation3;
    private javax.swing.JLabel jLabelLeftBlank;
    private javax.swing.JLabel jLabelNavigate;
    private javax.swing.JLabel jLabelRightBlank;
    private javax.swing.JLabel jLabelTime;
    private javax.swing.JMenuItem jMenuItemExit;
    private javax.swing.JPanel jPanelBar;
    private javax.swing.JPanel jPanelBotom;
    private javax.swing.JPanel jPanelMain;
    private javax.swing.JProgressBar jProgressBarProcess;
    private javax.swing.JPopupMenu.Separator jSeparator1;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JMenuItem pasteMenuItem;
    // End of variables declaration//GEN-END:variables

    private void saveAnswers() throws IOException {
        testRecord.setTestName(FileManager.STUDENT_ANSWER_FILE);
        this.manager.saveToFile(testRecord);
    }
//    public static void setQuestionNumber(int questionNumber) {
//        this.questionNumber = questionNumber;
//    }
//
//    public static int getQuestionNumber() {
//        return this.questionNumber;
//    }
//
//    public static void setFinishedQuestions(int finishedQuestions) {
//        this.finishedQuestions = finishedQuestions;
//    }
//
//    public int getFinishedQuestions() {
//        return this.finishedQuestions;
//    }
    

    
    
    public void timeOver(){
        try {
            // TODO add your handling code here:
            saveAnswers();
        } catch (IOException ex) {
            Logger.getLogger(QuestionPaperForm.class.getName()).log(Level.SEVERE, null, ex);
        }
        if (index + 1 < testRecord.getSectionsLength()) {
            this.jDialogSubmit.setSize(500, 200);
            this.jDialogSubmit.setAlwaysOnTop(true);
            this.jDialogSubmit.show();
        } else {
            this.jDialogFinish.setSize(500, 200);
            this.jDialogFinish.setAlwaysOnTop(true);
            this.jDialogFinish.show();
        }
        //new JProgressBar  
    }
}
